from django.db import models


# 行业表
class Industry(models.Model):
    name = models.CharField(max_length=20, unique=True)
    created = models.DateTimeField("创建时间", auto_now_add=True, null=True, blank=True)
    updated = models.DateTimeField("更新时间", auto_now=True, null=True, blank=True)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '行业'
        verbose_name_plural = verbose_name


# 区域表
class Area(models.Model):
    name = models.CharField(max_length=20, unique=True)
    created = models.DateTimeField("创建时间", auto_now_add=True, null=True, blank=True)
    updated = models.DateTimeField("更新时间", auto_now=True, null=True, blank=True)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '区域'
        verbose_name_plural = verbose_name


class User(models.Model):
    KIND_CHOICES = (
        (1, '行业'),
        (2, '区域'),
    )
    kind = models.IntegerField("类别", default=1, choices=KIND_CHOICES)
    industry = models.ForeignKey(Industry, on_delete=models.SET_NULL, verbose_name="行业", null=True, blank=True)
    area = models.ForeignKey(Area, on_delete=models.SET_NULL, verbose_name="区域", null=True, blank=True)
    isleader = models.IntegerField("是否领导", default=0)
    name = models.CharField("姓名", max_length=20)
    mobile = models.CharField("手机", max_length=20, unique=True)
    dept = models.CharField("部门", max_length=20)
    wxid = models.CharField("企业微信ID", max_length=20, unique=True, null=True, blank=True)
    GENDER_CHOICES = (
        (0, '未定义'),
        (1, '男'),
        (2, '女'),
    )
    gender = models.IntegerField("性别", default=0, choices=GENDER_CHOICES)
    avatar = models.CharField("头像url", max_length=128, null=True, blank=True)
    qrcode = models.CharField("员工个人二维码", max_length=128, null=True, blank=True)
    email = models.CharField("邮箱", max_length=20, null=True, blank=True)

    created = models.DateTimeField("创建时间", auto_now_add=True, null=True, blank=True)
    updated = models.DateTimeField("更新时间", auto_now=True, null=True, blank=True)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '客户经理'
        verbose_name_plural = verbose_name